4/16/2019

Background

Me

  • no coursework in CS; graph theory
  • not even intesive self-study
  • but I like R
  • and I have the internet

What's the deal?

Workflows

Work tends to go through a flow of steps.

How can we visualize this?

Micro$oft Visio?

Can we programmatically generate this?

What do I want?

  • people work in a tabular format to describe process
  • import table to R
  • ???
  • workflow diagram output

Bonus: multiple views of a single data source

One data source, multiple views

e.g.

  • simple diagram for external use
  • high detail, complex, for internal use

Example Data

mealslurry

mealslurry

Since I can't use department data … I'll use the process of making mealslurry

## # A tibble: 10 x 2
##    top.level.process     process        
##    <chr>                 <chr>          
##  1 acquire dry goods     online shopping
##  2 acquire dry goods     grocery store  
##  3 acquire grocery goods grocery store  
##  4 cooking               lentils        
##  5 cooking               cook           
##  6 cooking               blend          
##  7 portion               prep jars      
##  8 portion               load jars      
##  9 storage               cool           
## 10 storage               fridge

mealslurry data.frame

Column names represent what it would be called coming from a departmental process document (a so-called RACI table, Responsible, Accountable, Consulted, Informed)

## 'data.frame':    33 obs. of  3 variables:
##  $ top.level.process: chr  "acquire dry goods" "acquire dry goods" "acquire dry goods" "acquire dry goods" ...
##  $ process          : chr  "online shopping" "online shopping" "online shopping" "online shopping" ...
##  $ task.definition  : chr  "buy crickets" "buy curry powder" "buy whey powder" "citric acid" ...

R Code

DiagrammeR

package that uses Graphviz, mermaid, + .js libraries to make graph plots in R

Sweet, there's great documentation

Let's get started!

create_nodes(nodes = mealslurry$process)

Let's get started!

create_nodes(nodes = mealslurry$process)
Error in create_nodes(nodes = eat$process) : 
 could not find function "create_nodes"

so sad

Old documentation! :(

My process

piecing together documentation from the github page readme, a couple vignettes, and the manual

First moment of puzzlement

There doesn't seem to be documentation on how to go from tabular –> graph

Or ways to represent metadata over a set of nodes (like defining a group of connected nodes being part of a process), even thought it's present in Graphviz / DOT

A lot of functions serve to manipulate graph format data.

Graphviz / DOT

The majority of documentation / writing I encountered seemed to be using R as a Graphviz / DOT parser – writing a markup language and generating plots.

Here's the actual Graphviz page: https://graphviz.org/

Graphviz example

Resisting the urge to just use R to write DOT

Learning to use the package …

So, let's build up a graph

node_df + edge_df + create_graph = graph

Taking a subset of the larger process

cooking <- mealslurry %>% filter(top.level.process == "cooking")

node_df

n_cooking_tasks <- length(cooking$task.definition)

cooking_nodes <- create_node_df(n = n_cooking_tasks,
                             label = cooking$task.definition, 
                             type = cooking$process, # not sure what this is
                             # defining my own var
                             top_level_process = cooking$top.level.process) 

edges_df

cooking_edges <- create_edge_df(from = seq_len(n_cooking_tasks - 1), 
                             to = 2:n_cooking_tasks)

create_graph

cooking_graph <- create_graph(nodes_df = cooking_nodes,
                              edges_df = cooking_edges)

render_graph

render_graph(cooking_graph)

render_graph

render_graph(cooking_graph, layout = "kk")

render_graph

render_graph(cooking_graph, layout = "circle")

output = visNetwork

render_graph(cooking_graph, output = "visNetwork", layout = "circle")

… see more exploraton HTML for demo

What's next

Drawing the owl